package com.xspace.android.imcommon.interfaces;

import android.os.RemoteException;
import android.util.Log;

import com.xspace.android.imcommon.entity.MucChatMsgBean;

public class MucChatMg {
	private ServiceManager mServiceManager = null;
    public final static boolean isMUCROOMEnabled=false;
	private MucChatMg() {
		mServiceManager = ImServiceConnection.getInstance().getImServiceConnection();
	}

	private static MucChatMg instance = null;

	public static MucChatMg getInstance() {
		if (null == instance) {
			instance = new MucChatMg();
		}
		return instance;
	}
	//public String testRoomid="29ebc3f3abdf49ac9f79b48eb5fb7d8c";
	
	public String createMucRoom(final String nickname,final String userId){
		String roomjid=null;
		if(!isMUCROOMEnabled) return null;
		try {
			Log.v("imcommon", "createMucRoom>>"+nickname+" "+userId);
			roomjid=mServiceManager.CreateMucRoom(nickname, userId);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return roomjid;
	}
	
	public String SendMucmsg(MucChatMsgBean  mmb){
		String roomjid=null;
		if(!isMUCROOMEnabled) return null;
		if(mmb.mExHM.get("group_jid")==null){
		//	mmb.roomID=testRoomid;
		}
		else{
		//	mmb.roomID=mmb.mExHM.get("group_jid");
		}
		try {
			mServiceManager.sendMucMg(new MucChatAidl(mmb));
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return roomjid;
	}
	public void inviteFriendToRoom( String roomId,  String userId,
			 String reason) {
		//if(roomId==null) roomId=testRoomid;//测试x
		if(!isMUCROOMEnabled) return ;
		try {
			mServiceManager.inviteFriendToRoom(roomId, userId, reason);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	public void kickMemberFromRoom( String roomId, final String userId,
			final String reason) {
		if(!isMUCROOMEnabled) return ;
		try {
		//	if(roomId==null) roomId=testRoomid;//测试x
			mServiceManager.kickFriendFromRoom(roomId, userId, reason);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	public void joinToRoom(String roomId, final String userId, final String nickname) {
		if(!isMUCROOMEnabled) return ;
		try {
		//	if(roomId==null) roomId=testRoomid;//测试x
			mServiceManager.joinToRoom(roomId, userId, nickname);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	public void exitMucChat(String roomId) {
		if(!isMUCROOMEnabled) return ;
		try {
			//if(roomId==null) roomId=testRoomid;//测试x
			mServiceManager.exitMucRoom(roomId);
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
	
}
